<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="学校名称" prop="schoolName">
        <el-input v-model="queryParams.schoolName" placeholder="请输入学校名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学校简称" prop="schoolAliaeName">
        <el-input v-model="queryParams.schoolAliaeName" placeholder="请输入学校简称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属代理" prop="agentName">
        <el-input v-model="queryParams.agentName" placeholder="请输入所属代理" @click.native="openSelectAgent(1)" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系电话" prop="tel">
        <el-input v-model="queryParams.tel" placeholder="请输入联系电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系人" prop="contacts">
        <el-input v-model="queryParams.contacts" placeholder="请输入联系人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['zzedu:report:school']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="schoolinfoList">
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="学校全称" align="center" prop="schoolName" />
      <el-table-column label="联系人" align="center" prop="contacts" />
      <el-table-column label="联系电话" align="center" prop="tel" />
      <el-table-column label="招生人数" align="center" prop="studentCapacity" />
      <el-table-column label="实际招生人数" align="center" prop="realStudentCapacity">
        <template slot-scope="scope">
          <el-tag @click="openDetail(scope.row,'realStudentCapacity')">{{scope.row.realStudentCapacity}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="开班数量" align="center" prop="clzzNum">
        <template slot-scope="scope">
          <el-tag @click="openDetail(scope.row,'clzzNum')">{{scope.row.clzzNum}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="老师数量" align="center" prop="teacherNum">
        <template slot-scope="scope">
          <el-tag @click="openDetail(scope.row,'teacherNum')">{{scope.row.teacherNum}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="大屏数量" align="center" prop="deviceNum">
        <template slot-scope="scope">
          <el-tag @click="openDetail(scope.row,'deviceNum')">{{scope.row.deviceNum}}</el-tag>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 选择代理 -->
    <SelectAgent ref="selectAgent" :open="selectFlag" @selected-data="selectAgentData"
      @close-select-window="closeSelectAgent" />

    <school-student-report ref="realStudentCapacity"></school-student-report>
    <school-clzz-report ref="clzzNum"></school-clzz-report>
    <school-teacher-report ref="teacherNum"></school-teacher-report>
    <school-device-report ref="deviceNum"></school-device-report>
  </div>
</template>

<script>
  import {
    schoolReport,
  } from "@/api/bus_web/report/school_report";
  import {
    loadOptions
  } from "@/api/system/sys_region";
  import {
    isEmpty
  } from "@/utils/validate"
  import {
    isNumberStr
  } from '@/utils/index'
  import SelectAgent from "../agent/agent/select.vue"
  import SchoolStudentReport from "./school_student_report.vue"
  import SchoolClzzReport from "./school_clzz_report.vue"
  import SchoolTeacherReport from "./school_teacher_report.vue"
  import SchoolDeviceReport from "./school_device_report.vue"
  import {
    mapState
  } from 'vuex';
  import store from "@/store";
  export default {
    name: "School_report",
    components: {
      SelectAgent,
      SchoolStudentReport,
      SchoolClzzReport,
      SchoolTeacherReport,
      SchoolDeviceReport
    },
    data() {
      return {
        options: [],
        openTab: null,
        // 是否显示代理选择
        selectFlag: false,
        //选中代理
        selectedAgentData: [],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 学校管理表格数据
        schoolinfoList: [],
        // 弹出层标题
        title: "",
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          schoolName: null,
          schoolAliaeName: null,
          agentId: null,
          agentArray: [],
          agentName: null,
          schoolType: null,
          levelOfEducation: null,
          tel: null,
          introduce: null,
          province: null,
          city: null,
          district: null,
          address: null,
          state: null,
          queryProvinceAndCityAndDistrict: null,
        }
      };
    },
    created() {
      this.getList();
    },
    computed: {
      ...mapState({
        agent: state => state.selectAgent.agent,
        agentSelectModel: state => state.selectAgent.agentSelectModel
      })
    },
    methods: {
      /** 查询学校管理列表 */
      getList() {
        this.loading = true;
        schoolReport(this.queryParams).then(response => {
          this.schoolinfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.queryParams.orgId = null
        this.queryParams.orgIdArray = []
        this.handleQuery();

      },

      /** 导出按钮操作 */
      handleExport() {
        this.download('school/schoolinfo/exportReport', {
          ...this.queryParams
        }, `校区汇总数据_${new Date().getTime()}.xlsx`)
      },
      //选择代理
      openSelectAgent(selectVal) {
        this.selectFlag = true
        // selectVal =1 查询模式 =2 创建、修改模式
        this.$store.dispatch('selectAgent/cleanAgent')
        this.$store.dispatch('selectAgent/setAgentSelectModel', selectVal)
      },
      closeSelectAgent() {
        this.selectFlag = false
      },
      //确定代理
      selectAgentData() {
        this.closeSelectAgent()
        if (this.agentSelectModel == 2) {
          this.$set(this.form, 'agentName', this.agent[0].agentName)
          this.$set(this.form, 'agentId', this.agent[0].id)
          this.$refs.form.clearValidate(['agentName'])
        } else {
          this.queryParams.agentName = this.agent.map(item => item.agentName).join(',')
          this.queryParams.agentIdArray = this.agent.map(item => item.id)
        }
        this.$store.dispatch('selectAgent/cleanAgent')
      },
      // 实际招生人数列表
      openDetail(row, op) {
        this.$nextTick(() => {
          this.$refs[op].init(row)
        })
      }
    }
  };
</script>

<style>
</style>
